var util = require('../../../utils/util.js');
var ajax = require('../../../utils/ajax.js');
var common = require('../../../utils/common.js');
var PageBase = require('../../../common/PageBase.js');
var app = getApp();

Page(common.extendPage(PageBase, {
  data: {
    dataLoaded: false,
    toView: null,
    userInfo: {},
    shopList: {},
    floor:[],
    currentFloor: 0
  },

  onShareAppMessage: function (res) {
    return {
      title: "商城导览",
      path: '/pages/shop/list/list',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

  onLoad(options) {
    this._fetch();
  },
  onShow(){
    var toView = 'f' + app.getFloorId();
    var currentFloor = app.getFloorId();
    console.log(toView);
    this.setData({
      toView,
      currentFloor
    })
  },

  onPullDownRefresh() {
  },

  onReachBottom() {
  },

  _scrollToFloor(evt){

    var floorid = 'f' + evt.target.dataset.floorid;
      this.setData({
        toView: floorid,
        currentFloor: evt.target.dataset.floorid
      })
  },

  /**
   * 拉取页面数据
   * @return {[type]} [description]
   */
  _fetch(cb) {
    ajax.G({
      url: 'm=shop&c=index&a=all',
      data: {
        //storeid: this.data.storeid
      },
      success: (res) => {
        //debugger;
        var {
          hot = [],
          all = []
        } = res.data;
        //var newShopData = _doShopData(hot);
        var floor = [];
        var _length = all.length;
        for (var i = 1; i <= _length; i++){
          floor.push(i);
        }
        this.setData({
          dataLoaded: true,
          shopList: hot,
          shopAll: all,
          floor
        });
        cb && cb();
      },
      fail: () => {
        cb && cb();
      }
    });
  },

  /**
   * 重新组装楼层数据
   * @return {[type]} [description]
   */
  _doShopData(arr){ 
    //debugger;
     arr = arr.map((item) => function(){
       
     })
  }
  

}));